import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SPlayerGuildInfo } from "../../../../Message/Game/SPlayerGuildInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ModuleType } from "../../view/common/ModuleType";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { Cache } from "../../cache/Cache";
import { Guild } from "../../../../ModuleType/Guild";
//class GuildUpdateInfoCommand
    
    export  class GuildUpdateInfoCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc2=0;
            super.call(arg1);
            var loc1=arg1.messageBase as SPlayerGuildInfo;
            if (_cache.guild.myGuildInfo == null && loc1) 
            {
                if (!GuildUpdateInfoCommand.isFirstChange) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.HighlightGameUI, {"type":"Navbar", "name": Guild}));
                }
            }
            if (_cache.guild.myGuildInfo != null) 
            {
                loc2 = loc1.contribution - _cache.guild.myGuildInfo.contribution;
                if (loc2 > 0) 
                {
                    MsgManager.addTipText(Language.getStringByParam(57520, loc2));
                    MsgManager.showRollTipsMsg(Language.getStringByParam(57520, loc2));
                }
                else if (loc2 < 0) 
                {
                    MsgManager.addTipText(Language.getStringByParam(57521, Math.abs(loc2)));
                    MsgManager.showRollTipsMsg(Language.getStringByParam(57521, Math.abs(loc2)));
                }
                if (loc1.position != _cache.guild.myGuildInfo.position) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildPostionChange, loc1.position));
                }
            }
            if (loc1.guildId != 0) 
            {
                if (_cache.guild.myGuildInfo == null) 
                {
                    _cache.guild.myGuildInfo = loc1;
                    NetDispatcher.dispatchCmd(ServerCommand.GuildEnterGuild, null);
                }
                _cache.guild.myGuildInfo = loc1;
            }
            else 
            {
                if (_cache.guild.myGuildInfo != null) 
                {
                    _cache.guild.myGuildInfo = null;
                    NetDispatcher.dispatchCmd(ServerCommand.GuildLeaveGuild, null);
                }
                _cache.guild.myGuildInfo = null;
            }
            GuildUpdateInfoCommand.isFirstChange = false;
            Cache.instance.role.entityInfo.guildId = loc1.guildId;
            NetDispatcher.dispatchCmd(ServerCommand.GuildUpdateInfo, loc1);
            return;
        }

        private static /* var */isFirstChange: Boolean=true;
    }

            GuildUpdateInfoCommand.isFirstChange = true;
        